<?php
registerTable("user_notice", new table_user_notice());

class table_user_notice extends Database
{

    public function __construct()
    {
        parent::__construct("user_notice");
    }

    public function fetch_by_nid($nid)
    {
        return $this->fetch_assoc("`nid`='$nid'");
    }

    public function fetch_by_uid($uid)
    {
        return $this->fetch_all_assoc("`nid`='$uid'");
    }

    public function fetch_by_uid_limited($uid, $offset, $amount)
    {
        return $this->fetch_all_assoc("`uid` = $uid", "*","ORDER BY `date` DESC LIMIT $offset,$amount");
    }

    public function fetch_by_uid_not_read($uid)
    {
        return $this->fetch_all_assoc("`uid`='$uid' AND `is_read`=0");
    }

    public function fetch_by_uid_not_read_limited($uid, $offset, $amount)
    {
        return $this->fetch_all_assoc("`uid` = $uid AND `is_read` = 0","*", "ORDER BY `date` DESC LIMIT $offset,$amount");
    }

    public function read_all($uid)
    {
        return $this->update(array(
            "is_read" => 1
        ), "`uid`='$uid'", array(
            "is_read"
        ));
    }

    public function count_not_read($uid)
    {
        return $this->count_something("`uid`=$uid AND `is_read`=0");
    }
}
?>